#include<bits/stdc++.h>
using namespace std;
int n,cnt;
struct node
{
	int num,data;
};
queue <node> q,p;
void run1()
{
	while(q.size()){
		node temp=q.front();
		cout<<temp.num<<' ';
		cnt++;
		q.pop();
		node now=q.front();
		while(temp.data==now.data && q.size()){
			p.push(now);
			temp=now;
			q.pop();
			now=q.front();
		}
	}
	
}
void run2()
{
	while(p.size()){
		node temp=p.front();
		cout<<temp.num<<' ';
		cnt++;
		p.pop();
		node now=p.front();
		while(temp.data==now.data && p.size()){
			q.push(now);
			temp=now;
			p.pop();
			now=p.front();
		}
	}
}
int main()
{
	freopen("fruit.in","r",stdin);
	freopen("fruit.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		node a;
		scanf("%d",&a.data);
		a.data++;
		a.num=i;
		q.push(a);
	}

	while(cnt<n){
		run1();
		cout<<'\n';
		if(cnt>=n) return 0;
		run2();
		cout<<'\n';
	}
	return 0;
}

